<template>
  <div class="home-container" v-loading="loading">
    <div class="seek">
      <div class="seek-input">
        <el-input placeholder="UID/名称/电话" v-model="screeningPhone" clearable></el-input>
      </div>
      <div class="seek-btn">
        <el-button type="primary" icon="el-icon-search" @click="seek()">搜索</el-button>
      </div>
    </div>
    <el-table :data="tableData" border :default-sort = "{prop: 'userId', prop: 'createTime'}" style="width: 100%"   >
      <el-table-column  prop="userId" sortable label="UID"  ></el-table-column>
      <el-table-column  prop="name"  label="姓名"  ></el-table-column>
      <el-table-column  prop="phone"  label="电话"  ></el-table-column>
      <el-table-column  prop="createTime" sortable label="注册时间"  ></el-table-column>
      <el-table-column  prop="count1"  label="个人累计开单"  ></el-table-column>
      <el-table-column  prop="loanAmounts"  label="累计放款"  ></el-table-column>
      <el-table-column  prop="count2"  label="下属经纪人"  ></el-table-column>
      <el-table-column  prop="invitedby"  label="邀请人"  ></el-table-column>
      <el-table-column  prop="grade" label="等级" ></el-table-column>
      <el-table-column  prop="totalCommission"  label="累计佣金"  ></el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-button type="primary" size="mini"  @click="handleEdit(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="total" 
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"></el-pagination>


  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getToken, getLogindData, getPhone, getRoleid } from '@/utils/auth'
import { partnerList } from '@/api/teamManage'
export default {
  name: 'partner',
  data(){
    return{
      screeningPhone: '',
      tableData: [],
      total: 100,
      pageSize: 12,
      pageNum: 1,
      loading: true,
      isAdd: true
    }
  },
  created(){
    if(getRoleid() == '26') {
      this.isAdd = false
    } else {
      this.isAdd = true
    }
    this.getPartner(this.pageNum);
  },
  methods:{
    handleEdit(prop){
      this.$store.dispatch('user/setUserId',  prop.userId)
      // this.$router.push({name: 'PartnerDetail', params:{userId: prop.userId, grade: prop.grade}})
      this.$router.push({name: 'PartnerDetail', params:{grade: prop.grade}})
    },
    handleSizeChange(val) {},
    handleCurrentChange(val) {
      this.getPartner(val);
      this.loading = true;
    },
    getPartner(pageNum){
      let data = {
        token: getToken(),
        phone: this.screeningPhone,
        pageSize: 12,
        pageNum: pageNum
      }
      partnerList(data).then(response=>{
        if(response.state == '1') {
          this.loading = false;
          const { data } = response;
          
          this.tableData = data.list;
          this.total = data.total;
        }
      }).catch(error=>{
        console.log(error)
      })
    },
    
    seek(){
      this.getPartner(this.pageNum);
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  }
}
</script>

<style lang="scss" scoped>
.home-container{
    padding: 20px;
  }
  .el-table{
    min-height: 44rem;
  }
  .el-pagination{
    text-align: center;
    background-color: #fff;
    padding: 20px 0;
  }
  .seek{
    margin-bottom: 20px;
    display: flex;
    .seek-input{
      width: 300px;
    }
    .seek-btn{
      margin-left: 15px;
      button{
        padding: 12px 15px;
      }
    }
  }
  
</style>
